const express = require('express')
const app = express()
//
const bodyParser =require('body-parser')
//引入mongoose
const mongoose = require('mongoose')
const users =require('./routes/api/user')
const profiles =require('./routes/api/profiles')

const passport=require('passport')
const port = process.env.PORT || 5000
// 数据库信息
const db = require('./config/keys').mongoURI
//链接数据库
mongoose.connect(db)
    .then(() => console.log('数据库连接成功!!!'))
    .catch(err => console.log(err))
//使用bodyparser中间件
app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())
//passport初始化
app.use(passport.initialize())
require('./config/passport')(passport)
//使用routes
app.use('/api/users',users)
app.use('/api/profiles',profiles)

app.listen(port, () => console.log(`正在运行 http://127.0.0.1:${port} `))